package com.mission.schedule.email;


import android.support.annotation.NonNull;

import java.io.File;


public class SendMailUtil {

    //qq
    private static final String qqHOST = "smtp.qq.com";
    private static final String qqPORT = "587";//端口465或587
    private static String FROM_ADD = "";
    private static String FROM_PSW = "";

//    //163
    private static final String sinaHOST = "smtp.163.com";
    private static final String sinaPORT = "25"; //

    //outlook
    private static final String outlookHOST = "smtp.live.com";
    private static final String outlooksinaPORT = "25"; //587

    private static String HOST = "smtp.qq.com";
    private static String PORT = "587";

    public enum HostPort{
        QQ,
        SINA
    }


    public static Boolean send(final File file,String toAdd, HostPort port,String add, String pwd) {
        if (port == HostPort.QQ) {
            HOST = qqHOST;
            PORT = qqPORT;
        }
        if (port == HostPort.SINA) {
            HOST = sinaHOST;
            PORT = sinaPORT;
        }
        FROM_ADD = add;
        FROM_PSW = pwd;
        if (toAdd.equals("") || add.equals("") || pwd.equals("")) {
            return false;
        } else {
            final MailInfo mailInfo = creatMail(toAdd);
            final MailSender sms = new MailSender();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    sms.sendFileMail(mailInfo, file, HOST, FROM_ADD, FROM_PSW);
                }
            }).start();
        }
        return true;
    }


    public static void send(String toAdd){
        final MailInfo mailInfo = creatMail(toAdd);
        final MailSender sms = new MailSender();
        new Thread(new Runnable() {
            @Override
            public void run() {
                sms.sendTextMail(mailInfo);
            }
        }).start();
    }

    @NonNull
    private static MailInfo creatMail(String toAdd) {
        final MailInfo mailInfo = new MailInfo();
        mailInfo.setMailServerHost(HOST);
        mailInfo.setMailServerPort(PORT);
        mailInfo.setValidate(true);
        mailInfo.setUserName(FROM_ADD); // 你的邮箱地址
        mailInfo.setPassword(FROM_PSW);// 您的邮箱密码
        mailInfo.setFromAddress(FROM_ADD); // 发送的邮箱
        mailInfo.setToAddress(toAdd); // 发到哪个邮件去
        mailInfo.setSubject("时间表Excel文件"); // 邮件主题
        mailInfo.setContent("时间表Excel文件"); // 邮件文本
        return mailInfo;
    }

}